package cn.edu.scau.cmi.linyuetao.hibernate;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.Transaction;

import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;

public class Client extends Application{

	private Stage primaryStage;
	private Session session;
	private Transaction transaction;
	private StudentDAO studentDAO;
	private TeacherDAO teacherDAO;
	private Scene indexScene;
	private IndexController indexController;
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		launch(args);
	}

	@Override
	public void start(Stage primaryStage) throws Exception {
		// TODO Auto-generated method stub
		this.primaryStage = primaryStage;
		primaryStage.setTitle("Hibernate");
		session = HibernateSessionFactory.getSession();
		studentDAO = new StudentDAO();
		teacherDAO = new TeacherDAO();
		initStudentData();
		showIndexView();
	}
	
	private void initStudentData() {
		// TODO Auto-generated method stub
		
	}

	private void showIndexView() {
		// TODO Auto-generated method stub
		try {
            FXMLLoader loader = new FXMLLoader();
            loader.setLocation(Client.class.getResource("index.fxml"));
            AnchorPane rootLayout = (AnchorPane) loader.load();
            indexScene = new Scene(rootLayout);
            indexController = loader.getController();
            primaryStage.setScene(indexScene);
            indexController.setClient(this);
            primaryStage.show();
            
        } catch (Exception e) {
            e.printStackTrace();
        }
	}

	public Session getSession() {
		return session;
	}

	public void setSession(Session session) {
		this.session = session;
	}

	public Transaction getTransaction() {
		return transaction;
	}

	public void setTransaction(Transaction transaction) {
		this.transaction = transaction;
	}

	public StudentDAO getStudentDAO() {
		return studentDAO;
	}

	public void setStudentDAO(StudentDAO studentDAO) {
		this.studentDAO = studentDAO;
	}

	public TeacherDAO getTeacherDAO() {
		return teacherDAO;
	}

	public void setTeacherDAO(TeacherDAO teacherDAO) {
		this.teacherDAO = teacherDAO;
	}
}
